-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-120713: normalize year with century for datetime.strftime #120820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-120713: normalize year with century for datetime.strftime #120820
Conversation
reverted unit test
…acing the specifier with "%4Y"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that %G also needs a fix.
Right. It's now accounted for. The calculation of ISO-8601 year for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for addressing my comments.
I think that this is the right way to fix this problem, but we should still get confirmation from other core developers.
The code is much more complicated now with the support of "%G", and the C code has some bugs.
Co-authored-by: Erlend E. Aasland <[email protected]>
Thank you so much for taking the time to point me in the right direction! |
Thanks @blhsing for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
…ythonGH-120820) (cherry picked from commit 6d34938) Co-authored-by: blhsing <[email protected]>
Sorry, @blhsing and @serhiy-storchaka, I could not cleanly backport this to
|
GH-121144 is a backport of this pull request to the 3.13 branch. |
Thank you for your work and patience @blhsing. My apologies for our too picky reviews. |
…time (pythonGH-120820) (cherry picked from commit 6d34938) Co-authored-by: blhsing <[email protected]>
GH-121145 is a backport of this pull request to the 3.12 branch. |
…H-120820) (GH-121145) (cherry picked from commit 6d34938) Co-authored-by: blhsing <[email protected]>
…H-120820) (GH-121144) (cherry picked from commit 6d34938) Co-authored-by: blhsing <[email protected]>
…ime.strftime (pythonGH-120820) (pythonGH-121144)" This reverts commit 009618f.
…ime.strftime (pythonGH-120820) (pythonGH-121145)" This reverts commit 027902b.
|
On some platforms such as Linux,
datetime.strftime
does not 0-pad a year <= 999 when formatting with'%Y'
despite the documentation claiming an example output of "0001, 0002, …". The same issue applies when formatting with"%G"
.This PR fixes the issue by formatting a year with century with
'%04ld'
usingsprintf
(in C) or'{:04}'
usingstr.format
(in Python) if the platform is found to show the aforementioned behavior.datetime.strftime("%Y")
is not padding correctly #120713